package com.naiterui.ehp.bs.patient.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.patient.domain.MedicationRemind;

/**
 * <pre>
 *
 * </pre>
 *
 * @author fangguanhong
 * @date 2020/4/10 下午4:33
 * @since 1.0.0
 */
@Repository
public interface IApMedicationRemindRepository extends BaseJpaRepository<MedicationRemind, Long> {

    MedicationRemind findFirstByPatientId(Long patientId);

    @Query(nativeQuery = true, value = "select patient_id  as patientId ,remind_content  as remindContent, DATEDIFF(expire_at,now())   as " +
            "surplusDays  from  take_medication_remind  where  label_type = (label_type|?1) and   expire_at >= ?2")
    List<MedicationRemind> getMedicationRemindList(Integer labelType, Date queryDate);

    void deleteByPatientId(Long patientId);

    @Override
    MedicationRemind saveOrUpdate(MedicationRemind medicationRemind);
}
